var _timer = 30000;
var _split = 1;
var _id = 0;
var _status = "资料读取中...";

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;
var chkbutmod = false;
var b01_num = 0;
var b02_num = 0;
var b03_num = "";
var b11_num = 0;
var b12_num = 0;
var b13_num = "";
var account1 = "";
var account2 = "";
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=unow2&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i, j;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	show_rate0(a[0]);
	show_rate1(a[1]);
	show_rate2(a[2]);
	show_titleAmu(a[3]);
	window.status = "";
	
	// timer_id = setTimeout("timer()", _timer);
}

function show_rate2(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["rate2_"+i].innerHTML = rate;
		//if (count > 0) {
			document.all["amount2_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=6&numbers="+i+">"+Math.floor(amount)+"</a>";
			document.all["chg2_"+i].innerHTML = "<input type=checkbox id=rrr2_"+d2(i)+" onclick=\"quickrrr(2, "+i+")\">";
		/*
		} else {
			document.all["amount2_"+i].innerHTML = Math.floor(amount);
			document.all["chg2_"+i].innerHTML = "<input disabled type=checkbox id=rrr2_"+d2(i)+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win2_"+i].innerHTML = win1;
		document.all["win2_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function show_rate1(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["rate1_"+i].innerHTML = rate;
		//if (count > 0) {
			document.all["amount1_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=5&numbers="+i+">"+Math.floor(amount)+"</a>";
			document.all["chg1_"+i].innerHTML = "<input type=checkbox id=rrr1_"+d2(i)+" onclick=\"quickrrr(1, "+i+")\">";
		/*
		} else {
			document.all["amount1_"+i].innerHTML = Math.floor(amount);
			document.all["chg1_"+i].innerHTML = "<input disabled type=checkbox id=rrr1_"+d2(i)+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win1_"+i].innerHTML = win1;
		document.all["win1_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function show_rate0(str)
{
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = (a0[0]-0) / 6;
	for (i=1; i<50; i++) {
		a00 = a0[i].split("@");
		num = a00[0];
		num2 = (num < 10 ? "0"+num : num);
		rate = a00[1];
		count = a00[2]-0;
		amount = a00[3]-0;
		document.all["num0_"+i].innerHTML = num2;
		document.all["num0_"+i].className = "td1"+colors[g_numcolor[num]];
		document.all["rate0_"+i].innerHTML = rate;
		//if (count > 0) {
			document.all["amount0_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist1&dt1="+_open+"&dt2="+_open+"&bettype=77&numbers="+num2+">"+Math.floor(amount)+"</a>";
			document.all["chg0_"+i].innerHTML = "<input type=checkbox id=rrr0_"+d2(i)+" onclick=\"quickrrr(0, "+i+")\">";
		/*
		} else {
			document.all["amount0_"+i].innerHTML = Math.floor(amount);
			document.all["chg0_"+i].innerHTML = "<input disabled type=checkbox id=rrr0_"+d2(i)+">";
		}
		*/
		win1 = Math.floor(win - a00[4]);
		document.all["win0_"+i].innerHTML = win1;
		document.all["win0_"+i].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	document.all.amount0.innerHTML=Math.floor(amount0);
}
function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}
function quickrrr(c, i)
{
	if (document.all["rrr"+c+"_"+d2(i)].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
		// timer_id = setTimeout("timer()", 60000);
	}
}

function gen_rate0()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<5; i++)
		ret += _tb0head;
	ret += "</tr>";
	
	for (j=1; j<=10; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=0; i<5; i++) {
			k = i*10 + j;
			if (k > 49) {
				ret += "<td colspan=5>合计：<b id=amount0></b></td>";
			} else {
				ret += "<td id=num0_"+k+"></td><td nowrap id=amount0_"+k+"></td><td nowrap id=win0_"+k+"></td><td id=rate0_"+k+" class=rate></td><td id=chg0_"+k+" align=center></td>";
			}
		}
	}
	ret += "</table>";
	document.all.div0.innerHTML = ret;
}

function gen_rate1()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>"+_tb1head+""+_tb1head+"</tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center>"+_name1[1]+"</td><td nowrap id=amount1_1></td><td nowrap id=win1_1></td><td id=rate1_1 class=rate></td><td id=chg1_1 align=center></td>";
	ret += "<td class=td15 align=center>"+_name1[2]+"</td><td nowrap id=amount1_2></td><td nowrap id=win1_2></td><td id=rate1_2 class=rate></td><td id=chg1_2></td></tr>";
	ret += "</table>";
	document.all.div1.innerHTML = ret;
}

function gen_rate2()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>"+_tb1head+""+_tb1head+"</tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center>"+_name2[1]+"</td><td nowrap id=amount2_1></td><td nowrap id=win2_1></td><td id=rate2_1 class=rate></td><td id=chg2_1 align=center></td>";
	ret += "<td class=td15 align=center>"+_name2[2]+"</td><td nowrap id=amount2_2></td><td nowrap id=win2_2></td><td id=rate2_2 class=rate></td><td id=chg2_2 align=center></td></tr>";
	ret += "</table>";
	document.all.div2.innerHTML = ret;
}

function protect_all()
{
	var i = 0;
	var ii = 0;
	for (i=0; i<49; i++) {
		ii = i + 1;
		if (document.all["win0_"+ii].innerHTML-0 < 0) {
			if (document.all["rrr0_"+d2(ii)].checked) {
				document.all["rrr0_"+d2(ii)].checked = false;
				// timer_id = setTimeout("timer()", 1000);
			} else {
				document.all["rrr0_"+d2(ii)].checked = true;
				if (timer_id) clearTimeout(timer_id);
				// timer_id = setTimeout("timer()", 60000);
			}
		}
	}
}

function protect_b0()
{
	var cc = "";
	var i = 0;
	var ii = 0;
	var count = 0;
	var _err = 1;
	var _bet = new Array();
	var _num = new Array();
	b01_num = document.all.b41.value-0;
	b02_num = document.all.b42.value-0;
	b03_num = document.all.b43.value-0;
	account1 = document.all.usr1.value;
	if (b01_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b01_num > 9) {
		alert("不合理的赔率数值！");
	} else if (b02_num > 20) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b41", document.all.b41.value);
		SetCookie("b42", document.all.b42.value);
		if (b03_num > 0) {
			for (i=0; i<49; i++) {
				ii = i + 1;
				if (document.all["rrr0_"+d2(ii)].checked) {
					_err = 0;
					//if (document.all["amount0_"+ii].innerHTML-0 >= b03_num) {
						_bet[i] = 4;
						_num[i] = document.all["num0_"+ii].innerHTML;
						cc += _num[i]+"  →  "+b03_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("正码走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b01_num+"&back="+b02_num+"&nts="+b03_num+"&acc="+account1, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成");
				}
			} else {
				alert("没有勾选号码！");
			}
		}
	}
	b03_num = "";
	document.all.b43.value = b03_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b1()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b11_num = document.all.b11.value-0;
	b12_num = document.all.b12.value-0;
	b13_num = document.all.b13.value-0;
	account2 = document.all.usr2.value;
	if (b11_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b11_num > 3) {
		alert("不合理的赔率数值！");
	} else if (b12_num > 9) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b11", document.all.b11.value);
		SetCookie("b12", document.all.b12.value);
		if (b13_num > 0) {
			for (i=1; i<3; i++) {
				if (document.all["rrr1_"+d2(i)].checked) {
					//if (document.all["amount1_"+i].innerHTML-0 >= b13_num) {
						_bet[count] = 5;
						_num[count] = i;
						cc += (i==1 ? "总单" : "总双")+"  →  "+b13_num+"\n";
						count++;
					//}
				}
				if (document.all["rrr2_"+d2(i)].checked) {
					//if (document.all["amount2_"+i].innerHTML-0 >= b13_num) {
						_bet[count] = 6;
						_num[count] = i;
						cc += (i==1 ? "总大" : "总小")+"  →  "+b13_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("两面走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b11_num+"&back="+b12_num+"&nts="+b13_num+"&acc="+account2, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成");
				}
			}
		}
	}
	b13_num = "";
	document.all.b13.value = b13_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate0();
	gen_rate1();
	gen_rate2();
	b01_num = document.all.b41.value-0.00;
	b02_num = document.all.b42.value-0.00;
	b03_num = document.all.b43.value-0;
	account1 = document.all.usr1.value;
	b11_num = document.all.b11.value-0.00;
	b12_num = document.all.b12.value-0.00;
	b13_num = document.all.b13.value-0;
	account2 = document.all.usr2.value;
	chkbutmod = false;
	timer();
}

window.onload = winonload;